﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace FWMS
{
    public partial class MingxiSelectByPeriod : Form
    {
        public MingxiSelectByPeriod()
        {
            InitializeComponent();
        }

        private void MingxiSelectByPeriod_Load(object sender, EventArgs e)
        {
            //开始日期
            string startYear = this.startdate.Value.Year.ToString();
            string startMonth = this.startdate.Value.Month.ToString();
            this.startdate.Text = startYear + "年" + startMonth + "月" + "1日";

            //结束日期
            this.enddate.Value = System.DateTime.Now;
        }

        /**
         * 
         *  按时间段查询 查询按钮按下
         * */
        private void select_Click(object sender, EventArgs e)
        {
            Service.ChukumingxiService service = new FWMS.Service.ChukumingxiService();
            Bean.Chukumingxi_yuancailiaoBean bean = new FWMS.Bean.Chukumingxi_yuancailiaoBean();

            bean = service.mingxi_ServiceSelectByPeriod(this.startdate.Value, this.enddate.Value, COMMAND.CommandBean.cailiaostyle.ToString());

            if (bean != null && bean.Selectresult != null)
            {
                datagridviewadddata(bean, COMMAND.CommandBean.cailiaostyle);
            }
            else
            {

                MessageBox.Show("所选时间段内没有出库记录！", "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }

        }

        //接收数据并显示
        private void datagridviewadddata(Bean.Chukumingxi_yuancailiaoBean bean, int tabIndex)
        {
            this.btn_get.UseColumnTextForButtonValue = true;
            datagridview_mingxiSelectPeriodDetails.Rows.Clear();
            for (int j = 0; j < bean.Resultrow; j++)
                {
                    this.datagridview_mingxiSelectPeriodDetails.Rows.Add();
                    this.datagridview_mingxiSelectPeriodDetails.Rows[j].Cells[0].Value = bean.Selectresult[j, 0].ToString().Trim();
                    if (tabIndex == 0)
                    {
                        this.datagridview_mingxiSelectPeriodDetails.Rows[j].Cells[1].Value = "原料";
                    }
                    else if (tabIndex == 1)
                    {
                        this.datagridview_mingxiSelectPeriodDetails.Rows[j].Cells[1].Value = "调味料";
                    }
                    else if (tabIndex == 2)
                    {
                        this.datagridview_mingxiSelectPeriodDetails.Rows[j].Cells[1].Value = "辅料";
                    }
                    else if (tabIndex == 3)
                    {
                        this.datagridview_mingxiSelectPeriodDetails.Rows[j].Cells[1].Value = "半成品";
                    }
                    
                    this.datagridview_mingxiSelectPeriodDetails.Rows[j].Cells[2].Value = bean.Selectresult[j, 2].ToString().Trim();
                    this.datagridview_mingxiSelectPeriodDetails.Rows[j].Cells[3].Value = bean.Selectresult[j, 3].ToString().Trim();
                    this.btn_get.Text = "查看详细";

                }

                
            }

        private void datagridview_mingxiSelectPeriodDetails_CellMouseClick(object sender, DataGridViewCellMouseEventArgs e)
        {
            if (this.datagridview_mingxiSelectPeriodDetails.SelectedCells.Count == 0)
            {
                return;
            }
            
            if (this.datagridview_mingxiSelectPeriodDetails.SelectedCells[0].ColumnIndex == 4)
            {

                COMMAND.CommandBean.jijidate = this.datagridview_mingxiSelectPeriodDetails.Rows[this.datagridview_mingxiSelectPeriodDetails.SelectedCells[0].RowIndex].Cells[0].Value.ToString();
                COMMAND.CommandBean.jijiStartDay = this.datagridview_mingxiSelectPeriodDetails.Rows[this.datagridview_mingxiSelectPeriodDetails.SelectedCells[0].RowIndex].Cells[2].Value.ToString();
                COMMAND.CommandBean.jijiEndDay = this.datagridview_mingxiSelectPeriodDetails.Rows[this.datagridview_mingxiSelectPeriodDetails.SelectedCells[0].RowIndex].Cells[3].Value.ToString();
                this.Close();

            }
        }

        
    }
}
